package engine.display.Story.ActionControl 
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.flag.ObjType;
	import engine.flag.PlayerActionFlag;
	import engine.flag.ResourcesPath;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.text.NxLabel;
	import newx.com.loader.SwfLoader;
	
	/**
	 * ...
	 * @author WangHaiBo  www.woniu.com
	 */
	public class TalkActionPlay extends Sprite 
	{
		public static var RUN:String	=	"RUN";
		public static var WAIT:String	=	"WAIT";
		private var backMc:MovieClip
		private var roleMc:Sprite;
		private var _model:ModelLocator
		private var _key:String	=	"";
		private var _nameLabel:NxLabel;
		private var _titleLabel:NxLabel;
		private var _talkIconSpace:Sprite;
		private var _playStart:String	=	TalkActionPlay.WAIT;
		private var _bindManage:BindManage;
		private var _roleModel:int	=	-1;
		private var _configID:String	=	"";
		private var swfURL:String	=	"";
		public function TalkActionPlay() 
		{
			
			roleMc			=	new Sprite();
			_model			=	ModelLocator.getInstance();
			_bindManage		=	BindManage.getInstance();
			backMc			=	ResManager.newResClass("custSkin_86") as MovieClip;
			_nameLabel		=	new NxLabel();
			_titleLabel		=   new NxLabel();
			var glow:GlowFilter = new GlowFilter();
			glow.color = 0x000000;
			glow.alpha = 1;
			glow.blurX = 2;
			glow.blurY = 2;
			glow.strength = 8
			glow.quality = BitmapFilterQuality.MEDIUM;

			_nameLabel.txtFilters	=	[glow];
			_nameLabel.color=	0xFFFF00
			_nameLabel.text	=	""
			_nameLabel.y	=	-180;
			
			_titleLabel.txtFilters	= 	[glow];
//			_titleLabel.color=	0xFFFF00
			_titleLabel.text	=	""
			_titleLabel.y	=	-200;
			
			_talkIconSpace	=	new Sprite();
			_talkIconSpace.x	=	10;
			_talkIconSpace.y 	=	-215;
			
			this.addChild(_nameLabel);
			this.addChild(_titleLabel);
			this.addChild(roleMc);
			this.addChild(_talkIconSpace);
			this.PlayStart	=	_playStart;
			roleMc.addChild(backMc);
		}
		/**
		 * 设定人物模型
		 * @param	configID
		 */
		public function setSkin(configID:String):void
		{
			_configID	=	configID;
			swfURL		=	"";
			_bindManage.UnbindProp(_model.scene.Role, "Model",_roleModel);
			if (configID  == "-1")
			{
				_roleModel	=	_bindManage.BindProp(_model.scene.Role, "Model",this,"modelID");
			}
			else
			{
				var npcObj:Object	=	StaticIni.getIniObj(configID);
				if(npcObj != null)
				{
					if(npcObj["Type"]  == 2)
					{
						swfURL				=	ResPath.ACTORS + "npc_" + npcObj["Model"] + ".swf";
					}
					else if(npcObj["Type"]  == 6)
					{
						swfURL				=	ResPath.ACTORS + "funcnpc_" + npcObj["Model"] + ".swf";
					}
					
					SwfLoader.StartLoad(swfURL, null,loadOver);
				}

			}
		}
		/**
		 * 当前的人物模型的路径 
		 * @return 
		 * 
		 */		
		public function get skin():String
		{
			return swfURL;
		}
		/**
		 * 设定人物模型号
		 */
		public function set modelID(val:String):void
		{
			var swfURL:String	=	"";
			swfURL	=	ResourcesPath.getRoleModel(_model.scene.Role);
			SwfLoader.StartLoad(swfURL, null, loadOver);
			_bindManage.UnbindProp(_model.scene.Role, "Model",_roleModel);
		}
		/**
		 * 设定人物名称
		 * @param	str
		 */
		public function setName(str:String):void
		{
			_nameLabel.text	=	str;
			_nameLabel.x	=	-_nameLabel.width / 2;
			
		}
		
		/**
		 *设置称号 
		 * @param str
		 * 
		 */
		public function setTitleName(str:String):void
		{
			
			_titleLabel.text = str;
			
			_titleLabel.x = - _titleLabel.width/2;
		}
			
		
		public function loadOver(mc:MovieClip,pL:Array):void
		{
			if (mc != null)
			{
				while (roleMc.numChildren > 0 ) 
				{
					roleMc.removeChildAt(0);
				}
				if(mc.numChildren == 1 && mc.totalFrames == 1 )
				{
					mc = mc.getChildAt( 0 ) as MovieClip;
				}else
				{
					mc = ResManager.copy( mc ) as  MovieClip;
				}
				//换成原来的方法，可能有天会又用这个，保留
				//animation = new RangeAnimation();
				//if( ResManager.GetRess( String(_key)) == null )
				//{
				//	ResManager.SaveRess( String(_key), PixelUtil.mcPixel( mc as MovieClip ) );
				//}
				//animation.setBitmapData(  ResManager.GetRess( String(_key)));
				//animation.gotoAndPlay("wait");
				//animation.x = - ( animation.width / 2 );
				//animation.y = -animation.height;
				backMc	=	mc as MovieClip;
				this.PlayStart	=	_playStart;
				roleMc.addChild(mc);
			}
		}
		/**
		 * 设定人物的动作状态
		 */
		public function set PlayStart(val:String):void
		{
			
			_playStart	=	val;
			switch (_playStart) 
			{
				case TalkActionPlay.RUN:
					backMc.gotoAndPlay(PlayerActionFlag.Run);
				break;
				case TalkActionPlay.WAIT:
					if(_configID ==	"-1")
					{
						backMc.gotoAndPlay(PlayerActionFlag.NormalWait);
					}
					else
					{
						backMc.gotoAndPlay(PlayerActionFlag.Wait);
					}
					
				break;
				default:
			}
		}
		public function get PlayStart():String
		{
			return _playStart;
		}
		public function set ImageAlign(val:int):void
		{
			switch (val)
			{
				case 1:
					roleMc.scaleX	=	1;
					break;
				case 2:
					roleMc.scaleX	=	-1;
					break;
				default:
			}
		}
		/**
		 * 设定当前对话的表情图片 
		 * @param val
		 * 
		 */		
		public function set TalkIcon(val:String):void
		{
			clearIconSpace();
			_talkIconSpace.addChild(icon(val));
		}
		/**
		 * 清空表情容器里的图标
		 */		
		public function clearIconSpace():void
		{
			while(_talkIconSpace.numChildren > 0)
			{
				_talkIconSpace.removeChildAt(0);
			}
		}
		private function icon(val:String):MovieClip
		{
			var tempMc:MovieClip	=	new MovieClip();
			switch(val)
			{
				case "0":
					tempMc	=	ResManager.newResClass("TalkIcon") as MovieClip;
					break;
				case "1":
					tempMc	=	ResManager.newResClass("bq07") as MovieClip;
					break;
				case "2":
					tempMc	=	ResManager.newResClass("bq09") as MovieClip;
					break;
				case "3":
					tempMc	=	ResManager.newResClass("bq15") as MovieClip;
					break;
				case "4":
					tempMc	=	ResManager.newResClass("bq03") as MovieClip;
					break;
			}
			return tempMc;
		}

		/**
		 * 获取模型路径
		 * @param	modID
		 * @return
		 */
		private function getSkin(modID:String):String
		{
			_key	=	modID
			var tempStr:String	=	""
			switch (modID) 
			{
				case "12510006":
					tempStr	=	"41110106_ani_0";
				break;
				case "12510105":
					tempStr	=	"41110003_ani_0";
				break;
				case "11990101":
					tempStr	=	"41990101_ani_0";
				break;
				case "12510007":
					tempStr	=	"12710109_ani_0";
				break;
				case "12510047":
					tempStr	=	"12710205_ani_0";
				break;
				case "-1":
					tempStr	=	"31100001_ani_36010001";
				break;
				default:
			}
			return tempStr;
		}
		/**
		 * 半身像图片
		 * @param	val
		 */
		private function helfImage(val:String):void
		{
			var tempStr:String	=	"";
			switch (val) 
			{
				case "12510006":
					tempStr;
					break;
				default:
			}
		}
	}

}